import 'package:flutterproject/mvvm/base/base_controller.dart';
import 'package:flutterproject/page/mine/children/order/children/order_detail/data/order_detail_bean.dart';
import 'package:flutterproject/util/address_manager.dart';
import 'package:flutterproject/util/dialog_toast/dialog_util.dart';
import 'package:flutterproject/util/dialog_toast/toast_util.dart';
import 'package:flutterproject/util/http/http_client.dart';
import 'package:flutterproject/util/http/http_exception.dart';
import 'package:get/get.dart';

class OrderDetailController extends BaseController {
  HttpClient client = Get.find<HttpClient>();
  OrderDetailBean? orderDetailBean = OrderDetailBean();

  int? id = Get.arguments;

  @override
  void onReady() {
    super.onReady();
    getOrderDetail();
  }

  /// 获取订单详情
  Future getOrderDetail() async {
    try {
      DialogUtil.showLoading();
      orderDetailBean = await client.get<OrderDetailBean>(
          AddressManager.orderDetail,
          queryParameters: {"id": id});
      update();
      return true;
    } on HttpException catch (e) {
      ToastUtil.showFailed(e.message);
      return false;
    } finally {
      DialogUtil.dismiss();
    }
  }

  String getStatusStr(int? state) {
    switch (state) {
      case 1:
        return "待付款";
      case 2:
        return "待发货";
      case 3:
        return "已发货";
      case 4:
        return "完成";
      default:
        return "未知状态";
    }
  }
}
